package com.luoxiang.socialandroid.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.app.MyAppliaction;
import com.luoxiang.socialandroid.bean.UserDynamic;

import java.util.List;

public class SingleImageAdapter extends RecyclerView.Adapter<SingleImageAdapter.ViewHolder>{
    private List<UserDynamic> list;
    private String url = "https://dahuixiong.oss-cn-shenzhen.aliyuncs.com/";

    public SingleImageAdapter(List<UserDynamic> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_singleimage, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        UserDynamic bean = list.get(position);
        Glide.with(MyAppliaction.getContext())
                .load(url + bean.getUrl().get(0))
                .transform(new CenterCrop(),new RoundedCorners(16))
                .into(holder.im_single);
    }

    @Override
    public int getItemCount() {
        try {
            return list.size();
        }catch (Exception e){
            return 0;
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView im_single;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            im_single = itemView.findViewById(R.id.im_single);
        }
    }
}
